﻿using TreeSharp;

namespace SPR.Classes.Warrior
{
    using global::SPR.Helpers;

    class Arms : RotationBase
    {
        public override string Name
        {
            get { return "Arms Warrior"; }
        }

        public override string KeySpell
        {
            get { return "Bladestorm"; }
        }

        public override float CombatMaxDistance
        {
            get
            {
                return 5f;
            }
        }

        public override string Help
        {
            get
            {
                return "----------------------------------------------------------------------\n" +
                       "This Rotation will:\n" +
                       "1. Heal using Victory Rush, Enraged Regeneration\n" +
                       "==>             Rallying Cry, Healthstone \n" +
                       "2. AutomaticCooldowns has: \n" +
                       "==> UseTrinkets \n" +
                       "==> UseRacials \n" +
                       "==> UseEngineerGloves \n" +
                       "3. Stance Dance\n" +
                       "4. Best Suited for end game raiding\n" +
                       "NOTE: PvP uses single target rotation - It's not designed for PvP use. \n" +
                       "Credits to gniegsch\n" +
                       "----------------------------------------------------------------------\n";
            }
        }

        public override Composite SingleRotation
        {
            get
            {
                return new PrioritySelector(
                    new Decorator(
                            ret => Units.IsTargetWorthy(Me.CurrentTarget),
                                new PrioritySelector(
                                        Item.UseTrinkets(),
                                        Spells.UseRacials(),
                                        Buff.CastBuff("Lifeblood", ret => true, "Lifeblood"), // Thanks Kink
                                        Items.UseEngineerGloves(ret => true, "Engineer's gloves"))),
                        // Extra button automation
                        Items.RunMacroText("/click ExtraActionButton1", ret => (Units.IsFadingLight() || Units.IsShrapnel() || Units.IsHourofTwilight()) && SPR.Instance.AutoExtraActionButton, "[Push Button] ExtraActionButton1"),
                        // Interupts
                        Spells.CastInterupt("Pummel",                   ret => true, "Pummel"),
                        Spells.CastSelfSpell("Spell Reflection",        ret => Me.CurrentTarget.IsCasting, "Spell Reflection"), 
                        Spells.CastSpell("Rend",                        ret => Buff.PlayerHasBuff("Battle Stance") && !Buff.TargetHasDebuff("Rend"), "Rend"),
                        Spells.CastAreaSpell("Thunder Clap", 8, false, 2, 0.0, 0.0, a => Buff.PlayerHasBuff("Battle Stance") && Buff.TargetDebuffTimeLeft("Thunder Clap").TotalSeconds < 12.5 && Buff.TargetHasDebuff("Rend"), "TC Rend"),
                        Spells.CastAreaSpell("Sweeping Strikes", 8, false, 2, 0.0, 0.0, a => Buff.PlayerHasBuff("Berserker Stance"), "Sweeping Strikes"),
                        Spells.CastAreaSpell("Bladestorm", 8, false, 4, 0.0, 0.0, a => Buff.PlayerHasBuff("Berserker Stance") && Me.RagePercent > 40, "Bladestorm"),
                        Spells.CastAreaSpell("Cleave", 8, false, 2, 0.0, 0.0, a => Buff.PlayerHasBuff("Berserker Stance") && Buff.PlayerHasBuff("Battle Trance"), "Cleave BT"),
                        Spells.CastSpell("Overpower",                   ret => Buff.PlayerHasBuff("Battle Stance") && Buff.PlayerHasBuff("Taste for Blood") && Me.CurrentTarget.HealthPercent > 20, "Overpower"),
                        Spells.CastSpell("Mortal Strike",               ret => Buff.PlayerHasBuff("Berserker Stance"), "Mortal Strike"),
                        Spells.CastSpell("Colossus Smash",              ret => Buff.PlayerHasBuff("Berserker Stance") && (Buff.TargetDebuffTimeLeft("Colossus Smash").TotalSeconds < 1 || !Buff.TargetHasDebuff("Colossus Smash")), "Colossus Smash"),
                        Spells.CastSpell("Execute",                     ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent <= 20 && Buff.PlayerCountBuff("Executioner") <= 5 && Buff.PlayerBuffTimeLeft("Executioner").TotalSeconds <= 5, "Execute"),
                        Spells.CastSpell("Execute",                     ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent <= 20 && Me.RagePercent > 50, "Execute"),
                        Spells.CastAreaSpell("Cleave", 8, false, 2, 0.0, 0.0, a => Buff.PlayerHasBuff("Berserker Stance") && Me.RagePercent > 40, "Cleave"),
                        Spells.CastSpell("Heroic Strike",               ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent > 20 && Me.RagePercent > 85, "Heroic Strike"),
                        Spells.CastSpell("Heroic Strike",               ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent > 20 && Buff.PlayerHasBuff("Battle Trance"), "Heroic Strike"),
                        Spells.CastSpell("Heroic Strike",               ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent > 20 && Me.RagePercent > 75 && Buff.PlayerHasBuff("Inner Rage"), "Heroic Strike"),
                        Spells.CastSpell("Slam",                        ret => Buff.PlayerHasBuff("Berserker Stance") && Me.RagePercent > 50 && Me.CurrentTarget.HealthPercent > 20, "Slam"),
                        Spells.CastSpell("Deadly Calm",                 ret => Buff.PlayerHasBuff("Berserker Stance") && Buff.PlayerCountBuff("Slaughter") == 3, "Deadly Calm"),
                        Spells.CastSpell("Inner Rage",                  ret => Buff.PlayerHasBuff("Berserker Stance") && Me.CurrentTarget.HealthPercent > 20 && !Buff.PlayerHasBuff("Deadly Calm") && Buff.PlayerCountBuff("Slaughter") == 3, "Inner Rage"),
                        Spells.CastSpell("Berserker Rage",              ret => Buff.PlayerHasBuff("Berserker Stance") && !Buff.PlayerHasBuff("Deadly Calm"), "Berserker Rage"),
                        // Spells.CastSpell("Thunder Clap",                ret => !Buffs.UnitHasAttackSpeedDebuff(Me.CurrentTarget) && Buff.PlayerHasBuff("Battle Stance"), "Thunder Clap"),
                        // Spells.CastSpell("Demoralizing Shout",          ret => !Buffs.UnitHasDamageReductionDebuff(Me.CurrentTarget), "Demoralizing Shout"),
                        Spells.CastSpell("Battle Stance",               ret => !Buff.PlayerHasBuff("Recklessness") && Buff.PlayerHasBuff("Taste for Blood") && !Buff.PlayerHasBuff("Battle Stance") && Spells.SpellCooldown("Mortal Strike").TotalSeconds > 1.5 && Me.CurrentTarget.HealthPercent > 20, "Battle Stance"),
                        Spells.CastSpell("Battle Stance",               ret => !Buff.TargetHasDebuff("Rend") && (Me.CurrentTarget.CurrentHealth > 2000000 || Me.CurrentTarget.Name.Contains("Dummy")) && !Me.HasAura("Battle Stance"), "Battle Stance"),
                        Spells.CastSpell("Berserker Stance",            ret => !Buff.PlayerHasBuff("Berserker Stance"), "Berserker Stance"),
                        Buff.CastBuff("Battle Shout",                   ret => Me.RagePercent < 60, "Battle Shout"));
            }
        }

        public override Composite Medic
        {
            get
            {
                return new Decorator(
                    ret => Me.HealthPercent < 100,
                    new PrioritySelector(
                        Spells.CastSpell("Victory Rush",                ret => Me.HealthPercent < 80 && Buff.PlayerHasBuff("Victorious"), "Victory Rush"),
                        Spells.CastSelfSpell("Shield Wall",             ret => Me.HealthPercent < 35 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Enraged Regeneration"), "Shield Wall"),
                        Spells.CastSelfSpell("Enraged Regeneration",    ret => Me.HealthPercent < 45 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Shield Wall"), "Enraged Regeneration"),
                        Spells.CastSelfSpell("Rallying Cry",            ret => Me.HealthPercent < 45 && !Buff.PlayerHasBuff("Shield Wall") && !Buff.PlayerHasBuff("Enraged Regeneration"), "Rallying Cry"),
                        Items.UseBagItem("Healthstone",                 ret => Me.HealthPercent < 40 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Enraged Regeneration") && !Buff.PlayerHasBuff("Shield Wall"), "Healthstone")));
            }
        }

        public override Composite PreCombat
        {
            get
            {
                return new Decorator(
                        ret => !Me.Mounted && !Me.Dead && !Me.Combat && !Me.IsFlying && !Me.IsOnTransport && !Me.HasAura("Food") && !Me.HasAura("Drink"),
                        new PrioritySelector(
                            Buff.CastBuff("Battle Shout", ret => !Buff.PlayerHasBuff("Battle Shout"), "Battle Shout")));
            }
        }

        public override Composite PVPRotation
        {
            get
            {
                return SingleRotation;
            }
        }

        public override Composite PVERotation
        {
            get
            {
                return SingleRotation;
            }
        }
    }
}
